pass `-C ar`/`-C linker` when building native dylibs/plugins
authorJorge Aparicio <japaricious@gmail.com>
Tue, 14 Apr 2015 06:50:00 +0000 (01:50 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Tue, 14 Apr 2015 06:51:57 +0000 (01:51 -0500)
closes #1515

src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_compile_plugins.rs

index 5617135d9cacb362cc90db07b742b4dd9c723ee6..3a4863abf60f8e754577ec83b6ecf2f8aa8cc2bc 100644 (file)
@@ -694,21 +694,22 @@ fn build_base_args(cx: &Context,
 
 fn build_plugin_args(cmd: &mut CommandPrototype, cx: &Context, pkg: &Package,
                      target: &Target, kind: Kind) {
+    fn opt(cmd: &mut CommandPrototype, key: &str, prefix: &str,
+           val: Option<&str>)  {
+        if let Some(val) = val {
+            cmd.arg(key).arg(&format!("{}{}", prefix, val));
+        }
+    }
+
     cmd.arg("--out-dir").arg(&cx.out_dir(pkg, kind, target));
     cmd.arg("--emit=dep-info,link");
 
     if kind == Kind::Target {
-        fn opt(cmd: &mut CommandPrototype, key: &str, prefix: &str,
-               val: Option<&str>)  {
-            if let Some(val) = val {
-                cmd.arg(key).arg(&format!("{}{}", prefix, val));
-            }
-        }
-
         opt(cmd, "--target", "", cx.requested_target());
-        opt(cmd, "-C", "ar=", cx.ar(kind));
-        opt(cmd, "-C", "linker=", cx.linker(kind));
     }
+
+    opt(cmd, "-C", "ar=", cx.ar(kind));
+    opt(cmd, "-C", "linker=", cx.linker(kind));
 }
 
 fn build_deps_args(cmd: &mut CommandPrototype,
index f293968fa1395ed04f8638de60c2511c74946d03..e5c4e979a3cdc005f15905fb4e4213c4ff0a7f92 100644 (file)
@@ -2,6 +2,7 @@ use std::fs;
 use std::env;
 
 use support::{project, execs};
+use support::{COMPILING, RUNNING};
 use hamcrest::assert_that;
 
 fn setup() {
@@ -219,3 +220,50 @@ test!(doctest_a_plugin {
     assert_that(p.cargo_process("test").arg("-v"),
                 execs().with_status(0));
 });
+
+// See #1515
+test!(native_plugin_dependency_with_custom_ar_linker {
+    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+
+    let foo = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            name = "foo"
+            plugin = true
+        "#)
+        .file("src/lib.rs", "");
+
+    let bar = project("bar")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            name = "bar"
+
+            [dependencies.foo]
+            path = "../foo"
+        "#)
+        .file("src/lib", "")
+        .file(".cargo/config", &format!(r#"
+            [target.{}]
+            ar = "ar"
+            linker = "cc"
+        "#, target));
+
+    foo.build();
+    assert_that(bar.cargo_process("build").arg("--verbose"),
+    execs().with_stdout(&format!("\
+{compiling} foo v0.0.1 ({url})
+{running} `rustc [..] -C ar=ar -C linker=cc [..]`
+{compiling} bar v0.0.1 ({url})
+{running} `rustc [..] -C ar=ar -C linker=cc [..]`
+", compiling = COMPILING, running = RUNNING, url = bar.url())))
+});